package org.sol.tools.commands;

import java.util.ArrayList;
import java.util.List;

public abstract class Command {
	
	private String name;
	private String description;
	private List<Argument> arguments = new ArrayList<Argument>();
	private String tailDescription;
	private boolean tailRequired = true;
	private boolean tailMany = true;
	
	private List<String> values = new ArrayList<String>();
	
	public String getName() {
		return name;
	}
	public String getDescription() {
		return description;
	}
	public List<Argument> getArguments() {
		return arguments;
	}
	public String getTailDescription() {
		return tailDescription;
	}
	public boolean isTailRequired() {
		return tailRequired;
	}
	public boolean isTailMany() {
		return tailMany;
	}
	
	public List<String> getValues() {
		return values;
	}

	public String help() {
		StringBuilder string = new StringBuilder();
		
		string.append(String.format("%s [arguments] %s%s\n", name, tailDescription, tailMany ? "..." : ""));
		string.append(String.format("\t%s\n", description));
		for (Argument argument : arguments) {
			string.append(argument.help());
		}
		
		return string.toString();
	}
	
	public abstract boolean validate();
	protected void setName(String name) {
		this.name = name;
	}
	protected void setDescription(String description) {
		this.description = description;
	}
	protected void setArguments(List<Argument> arguments) {
		this.arguments = arguments;
	}
	protected void setTailDescription(String tailDescription) {
		this.tailDescription = tailDescription;
	}
	protected void setTailRequired(boolean tailRequired) {
		this.tailRequired = tailRequired;
	}
	protected void setTailMany(boolean tailMany) {
		this.tailMany = tailMany;
	}
	protected void setValues(List<String> values) {
		this.values = values;
	}
}
